package mao.designmode.singleton;

import java.io.IOException;
import java.util.Properties;

/*
单例模式第二种，静态代码块;
优点：可以更具属性文件配置类，不用再代码中写死。
 */
public class Singleton2 {
    public  static  Singleton2 INSTANCE = null;
    private String info = null;
    static {
        Properties pro = new Properties();
        try {
            pro.load(Singleton2.class.getClassLoader().getResourceAsStream("java.txt"));
            String info1 = pro.getProperty("info");
            INSTANCE = new Singleton2(info1);
        }catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    private Singleton2(String info){
        this.info = info;
    }
    public String getInfo() {
        return info;
    }
}
